<?php 
include_once('includes.php'); 	


if(isset($_GET["match_id"]) && $_GET["match_id"]>0 )
{
	$match_id = (int) $_GET["match_id"];
		
	$sql = "select  highlights.id as hid, highlights.* ,matchs.*, competition.name as cname from matchs left join competition on matchs.competition_id = competition.id  left join highlights on highlights.match_id = matchs.id where  status=2 and matchs.id=".$match_id;
	$highlight=db_fetch_one($sql);
	
	if(isset($_GET["task"]) && $_GET["task"] == "delete" )
	{
		db_delete("highlights",$highlight->hid );
		Header("Location: /admin/highlights");
		exit;
	}
	
		
}

if($_SERVER["REQUEST_METHOD"]=="POST")
{
	$id = $_POST["id"];
	$data["id"] = $id;
	$data["match_id"] = $_POST["match_id"];
	$data["score"] = $_POST["goals1"]."-".$_POST["goals2"];
	$data["content"] = $_POST["content"];
	if (get_magic_quotes_gpc()) {
		$data["content"] = stripslashes($_POST["content"]);
	}
	
	if($data["id"] >0 )
		db_update("highlights",$data["id"],$data);
	else
		db_insert("highlights",$data);		
	
	Header("Location: /admin/highlights");
	exit;
}

list($team1, $team2 ) = split('-',$highlight->versus);
$team1 = trim($team1);
$team2 = trim($team2);		
list($goals1, $goals2 ) = split('-',$highlight->score);
?>
<?php include_once('includes/header.php'); 	 ?>
<span class="title">Create Highlight</span>


<form name="submitform" method="post" action="">
	<input type="hidden" name="id" value="<?php echo $highlight->hid;?>"/>
	<input type="hidden" name="match_id" value="<?php echo $match_id;?>"/>
	<p>
		<strong style="font-size:16px">
		 <?php echo $team1;?> 
		<select name="goals1" style="width:50px">
		<?php 
		for($i=0;$i<=15;$i++) 
		{
			$selected  = ($goals1==$i)?"selected='selected'":"";
			echo '<option value="'.$i.'"  '.$selected.'>'.$i.'</option>';
		}	
		?>
		</select>
		-
		<select name="goals2" style="width:50px">
		<?php 
		for($i=0;$i<=15;$i++)
		{
			$selected  = ($goals2==$i)?"selected='selected'":"";
			echo '<option value="'.$i.'"  '.$selected.'>'.$i.'</option>';
		}	
		?>
		</select>
		<?php echo $team2;?> 
		</strong>
	</p>
	<p>
		Content Highlight<br/>
		<textarea name="content" style="width:100%; height:500px"><?php echo $highlight->content;?></textarea>
	</p>
	
	
	<div class="button"> <input type="submit" value="Save"/>   <input type="button" value="Cancel" onclick="history.go(-1);"/>     </div>
</form>

<?php include_once('includes/footer.php'); 	 ?>